package com.android.common.network;

import com.android.common.base.BaseEvent;
import com.android.common.base.BaseView;
import com.android.common.constant.Constant;
import java.util.Objects;
import org.greenrobot.eventbus.EventBus;

/**
 * @param <T>
 */
public class BusinessObserver<T> extends ResponseObserver<ResponseBean<T>>{

    public BusinessObserver(BaseView baseView ,String methodName){
        super(baseView,methodName);
    }
    @Override
    protected void onSuccess(ResponseBean<T> responseBean) {
        if (responseBean.getCode() == Constant.SUCCESS){
            onSucceed(responseBean.getData(),mMethodName);
        }else if (responseBean.getCode() == Constant.LOGOUT){
            EventBus.getDefault().post(new BaseEvent(BaseEvent.LOGIN));
        }else {
            failed(responseBean.getCode(),responseBean.getMessage());
        }
    }

    public void onSucceed(T t,String methodName){
        Objects.requireNonNull(mBaseView).onSucceed(t,methodName);
    }
}
